#!/bin/sh

# URL format:http://libsyn.com/media/eslpod/ESLPod923.mp3
# This shell doesn't download the NO. smaller than 100, because their
# format are not unique.

URL_BASE="http://libsyn.com/media/eslpod/ESLPod"
FILE_EXTEN=".mp3"

if [ ! $# -eq 2 ];then
	echo 'Wrong parameters'
	echo "Usage: ./$0 begin_no end_no"
	exit 1
fi

BEGIN_NO=$1
END_NO=$2

DL_DIR=ESLPodcast

if [ ! -d $DL_DIR ];then
	mkdir $DL_DIR
fi

while [ $BEGIN_NO -le $END_NO ];do
	if [ -f $DL_DIR/ESLPod$BEGIN_NO$FILE_EXTEN ];then
		echo "ESLPOD$BEGIN_NO exists."
	else
		echo "Downloading... $URL_BASE$BEGIN_NO$FILE_EXTEN"
		(cd $DL_DIR;wget $URL_BASE$BEGIN_NO$FILE_EXTEN)
	fi
	BEGIN_NO=`expr $BEGIN_NO + 1`
done

if [ $? -eq 0 ];then
	echo "Finish"
else
	echo "Fail"
fi

